<extend name="work/base"/>
<block name="content">
    <!-- case-content -->
    <div class="case-content news_back">
        <div class="news-flow">
            <div class="layui-fluid pb50">
                <div class="layui-row item-list-box layui-clear" id="item-list-box" style="margin:0">
                </div>
            </div>

        </div>

    </div>
    <div id="demo0" style="text-align: center;"></div>
    </div>


    <!-- end case-content -->
</block>
<block name="script">
    <script type="text/javascript">
        layui.use(['carousel', 'jquery', 'element', 'laypage', 'layer'], function () {
            var carousel = layui.carousel
                , laypage = layui.laypage
                , element = layui.element
                , layer = layui.layer
                , $ = layui.$;
            laypage.render({
                elem: 'demo0'
                , limit: 20
                , count: {$count} //数据总数
                , jump: function (obj, first) {
                    if (obj.curr) {
                        refresh(obj.curr)
                    } else {
                        refresh(1)
                    }
                    return false;
                }
            });

            function refresh(curr) {
                // console.log(count)
                // console.log(curr)
                $.ajax({
                    url: "{:url('/home/news/index')}",
                    type: 'post',
                    dataType: 'json',
                    data: {
                        page: curr,
                    }
                })
                    .done(function (res) {
                        if (res.data == null) {
                            layer.msg('没有更多内容', {
                                time: 1500,
                                icon: 5
                            });
                        } else {
                            $("#item-list-box").html('');
                            $.each(res.data, function (i, n) {
                                var htmlstr = '<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">\n' +
                                    '                            <a href="/home/news/info?id=' + n.id + '">\n' +
                                    '                                <div class="item">\n' +
                                    '                                    <div class="item-text">\n' +
                                    '                                        <h3>' + n.title + '</h3>\n' +
                                    '                                        <span>' + n.category_id + '</span>\n' +
                                    '                                        <span>' + n.c_time + '</span>\n' +
                                    '                                    </div>\n' +
                                    '                                </div>\n' +
                                    '                            </a>\n' +
                                    '                        </div>';

                                $("#item-list-box").append(htmlstr)
                            });
                        }
                    })
                    .fail(function () {
                        layer.msg('服务器异常', {
                            time: 1500,
                            icon: 5
                        });
                    })
                    .always(function () {

                    });

            }

            refresh(1);

            $('.app-header-menuicon').on('click', function () {
                $('.header-down-nav').toggleClass('down-nav')
            })

        });
    </script>
</block>